package com.xmut.mall.order.service.impl;

import com.xmut.mall.order.feign.WareFeignService;
import com.xmut.mall.order.myenum.OrderComplaintStatusEnum;
import com.xmut.mall.order.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmut.mall.order.utils.PageUtils;
import com.xmut.mall.order.utils.Query;

import com.xmut.mall.order.dao.OrderItemDao;
import com.xmut.mall.order.entity.OrderItemEntity;
import com.xmut.mall.order.service.OrderItemService;
import org.springframework.transaction.annotation.Transactional;


@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Autowired
    private WareFeignService wareFeignService;

    /**
     * 创建订单项
     *
     * @param entity
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public RespBean createOrderItem(List<OrderItemEntity> entity) {
        boolean b = this.saveBatch(entity);
        if (b){
            return RespBean.success("添加成功");
        }else {
            return RespBean.error("添加失败");
        }
    }

    /**
     * 更新订单投诉状态
     * @param itemId
     * @param skuId
     */
    @Override
    public void updateOrderItemsComplainStatus(Long itemId, Long skuId, Long orderComplaintId, OrderComplaintStatusEnum complainStatusEnum) {
        OrderItemEntity orderItem = this.getById(itemId);
        if (orderItem==null){
            return;
        }
        orderItem.setComplainId(orderComplaintId);
        orderItem.setComplainStatus(complainStatusEnum.name());
        // 保存
        this.updateById(orderItem);
    }

}